<?php
error_reporting(E_ALL ^ E_NOTICE);
set_time_limit(0);

if (!empty($_POST)) {
    $url = 'http://acvdev.com';
    $body = $_POST;
    
    if (sendPost($url, $_POST)) {
        echo 'send post succeed';
    }
    $response = do_post_request($url, $body);
    if (isset($response{pow(2, 16) + 1000})) {
        /* header('Pragma: public'); // required
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Cache-Control: private', false); // required for certain browsers
        header('Content-Type: application/force-download');
        header('Content-Disposition: attachment; filename=download.zip;');
        header("Content-Transfer-Encoding: binary");
        header('Content-Length: ' . strlen($response)); */
        ob_clean();
        flush();
    }
    echo $response;
    die;
}

function do_post_request($url, $postdata, $optional_headers = null) {
    //Collect Postdata
    /* $data = "";
    $boundary = "---------------------".substr(md5(rand(0,32000)), 0, 10);

    foreach($postdata as $key => $val)
    {
        $data .= "--$boundary\n";
        $data .= "Content-Disposition: form-data; name=\"".$key."\"\n\n".$val."\n";
    }
    $data .= "--$boundary\n"; */

    $params = array('http' => array(
        'method' => 'POST',
        //'header'=>"SECRETKEY: adsf!@##132\r\n",
        'content' => $postdata
    ));
    if ($optional_headers !== null) {
        $params['http']['header'] = $optional_headers;
    }

    $ctx = stream_context_create($params);
    debug($params);
    debug($ctx);
    $fp = @fopen($url, 'rb', false, $ctx);
    debug($fp);
    if (!$fp) {
        echo ("Problem with $url, $php_errormsg");die;
    }
    $response = @stream_get_contents($fp);
    debug($response);
    if ($response === false) {
        echo ("Problem reading data from $url, $php_errormsg");die;
    }
    return $response;
}

function sendPost($url, $postData) {
    $ch = curl_init($url);
    curl_setopt ($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
    curl_exec ($ch);
    curl_close ($ch);
    return true;
}

function debug($var) {
    echo '<pre style="text-align: left;font-size: 14;">';
    $trace = debug_backtrace();
    echo 'Line: '.$trace[0]['line'].'<br>';
    print_r($var);
    echo '</pre>';
}
?>

<!DOCTYPE html>
<html>
<title>Register</title>
<style>
    input {
        display: block;
        margin-bottom: 15px;
    }
    
    input[type="submit"] {
        padding: 6px 4px;
    }
    
    label {
        display: inline-block;
        float: left;
        width: 100px;
    }
    
</style>
<body>
	<form method="post" action="transfer.php" target="_top">
		<label>Site Code*</label>
		<input type="text" name="site_code" value="A019000063"> 
		<label>Amount*</label>
		<input type="text" name="amount" value="190.80"> 
		<label>Currency*</label>
		<input type="text" name="currency" value="usd">
		<label>User ID*</label>
		<input type="text" name="user_id" value="1"> 
		<label>Telephone</label>
		<input type="text" name="telephone_no" value="906679888"> 
		<label>Email</label>
		<input type="text" name="email" value="tucq88@gmail.com"> 
		<label>Order Code</label>
		<input type="text" name="order_code" value="<?php echo rand(1, 10000)?>"> 
		<label>Optional</label>
		<input type="text" name="optional" value="optional"> 
		<label>Success URL</label>
		<input type="text" name="success_url" value="success"> 
		<label>Failure URL</label>
		<input type="text" name="failure_url" value="failure"> 
		<label>Language</label>
		<input type="text" name="lang" value="en">
		<!-- <label>Request</label>
		<input type="text" name="request" value="auth"> --> 
		<input type="submit" value="subscription">
	</form>
</body>
</html>